clear all



*----------------------------------------------------------------
import delimited "..\dataRaw\Cropland_AcresHarvested_Irrigated_census.csv", clear

rename stateansi stfips
rename countyansi cofips
rename value acresh

* The "D" flag denotes that they withheld data to avoid disclosing data
* for individual produers
gen flag="D" if acresh=="(D)"
replace flag="D" if acresh==" (D)"

destring acresh, replace ignore(" (D)" "(D)" ",")

* missing cofips code in Alaska
* drop that data
drop if cofips==.

* Specify 2 practices
* irr - Irrigated
* non - Nonirrigated
gen str3 practice=""
replace practice="Irr" if 	dataitem=="AG LAND, CROPLAND, HARVESTED, IRRIGATED - ACRES" 
replace practice="Non" if 	dataitem=="AG LAND, CROPLAND, HARVESTED - ACRES" 

rename acresh acresh_	
keep stfips cofips year practice acresh_ flag	

reshape wide acresh_ flag, i(stfips cofips year) j(practice) string

replace acresh_Irr=0 if acresh_Irr==. & flagIrr!="D"
replace acresh_Non=0 if acresh_Non==. & flagNon!="D"


drop flag*

reshape wide acresh*, i(stfips cofips) j(year)

save "..\temp\acresHarvested_county", replace



*----------------------------------------------------------------
import delimited "..\dataRaw\Cropland_AcresFallowIdleFailed_census.csv", clear

rename stateansi stfips
rename countyansi cofips
rename value acres

* The "D" flag denotes that they withheld data to avoid disclosing data
* for individual produers
gen flag="D" if acres=="(D)"
replace flag="D" if acres==" (D)"

destring acres, replace ignore(" (D)" "(D)" ",")

* missing cofips code in Alaska
* drop that data
drop if cofips==.

gen str3 practice=""
replace practice="Fallow" if 	dataitem=="AG LAND, CROPLAND, (EXCL HARVESTED & PASTURED), CULTIVATED SUMMER FALLOW - ACRES" 
replace practice="Idle" if 	dataitem=="AG LAND, CROPLAND, (EXCL HARVESTED & PASTURED), IDLE - ACRES" 
replace practice="Failed" if 	dataitem=="AG LAND, CROPLAND, (EXCL HARVESTED & PASTURED), ALL CROPS FAILED - ACRES" 

rename acres acres_	
keep stfips cofips year practice acres_ flag	

reshape wide acres_ flag, i(stfips cofips year) j(practice) string

replace acres_Fallow=0 if acres_Fallow==. & flagFallow!="D"
replace acres_Idle=0 if acres_Idle==. & flagIdle!="D"
replace acres_Failed=0 if acres_Failed==. & flagFailed!="D"

drop flag*

reshape wide acres*, i(stfips cofips) j(year)

save "..\temp\FallowIdleFailed_county", replace





